package com.hualan.controller;

import com.hualan.domain.Publicity;
import com.hualan.service.PublicityService;
import com.hualan.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/publicityController")
public class PublicityController {
    @Autowired
    private PublicityService publicityService;


    @PostMapping("/selectAllPublicity")
    public R selectAllPublicity(){
        return publicityService.selectAllPublicity();
    }
    @GetMapping("/selectAllByPage")
    public R selAllFreePage(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,@RequestParam(name = "pageSize",defaultValue = "5")int pageSize){
        return R.success(publicityService.selAllByPage(pageNum,pageSize));
    }



    @DeleteMapping("deleteByPrimaryKey")
    public R deleteByPrimaryKey(int  id){
        return publicityService.deleteByPrimaryKey(id);
    }

    @PostMapping("/insert")
    public R insert(String name, String publicitytext){
        Publicity publicity=new Publicity();
        publicity.setName(name);
        publicity.setPublicitytext(publicitytext);
        System.out.println(publicity);
        return publicityService.insert(publicity);
    }

    @PostMapping("/updateByPrimaryKey")
    public R updateByPrimaryKey(Publicity publicity){

        System.out.println(publicity);
        return publicityService.updateByPrimaryKey(publicity);
    }

    @GetMapping("/selectPublicityLike")
    public     R selectPublicityLike(String name, String publicityText){
        return publicityService.selectPublicityLike(name, publicityText);
    }

    public static void main(String[] args) {
        Publicity publicity=new Publicity("name","context");
        System.out.println(publicity);
//        return publicityService.insert(publicity);
    }
}
